/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Mirza
 */
public class Barang extends DatabaseModel {

    public String kodeBarang;
    public String namaBarang;
    public String stok;
    public String barcode;

    public Barang() {
        super();
    }

    @Override
    public boolean insertTransaction() {
        try {
            String sql = "insert into barang(`nama_barang`,`stok`,`barcode`) values('" +namaBarang+ "','" + stok + "','" + barcode + "')";
            super.statement.execute(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(Barang.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    @Override
    public boolean updateTransaction() {
        try {
            String sql = "update barang set nama_barang = '" + namaBarang + "', stok = '" + stok + "', barcode = '" + barcode + "' where kode_barang = '" + kodeBarang + "' ";
            super.statement.execute(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(Barang.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    @Override
    public boolean deleteTransaction() {
        try {
            String sql = "delete from barang where kode_barang = '" + kodeBarang + "'";
            super.statement.execute(sql);
            return true;
        } catch (SQLException ex) {
            Logger.getLogger(Barang.class.getName()).log(Level.SEVERE, null, ex);
        }
        return false;
    }

    @Override
    public ResultSet getData(String filter) {
        try {
            String sql = "select * from barang " + filter;
            return super.statement.executeQuery(sql);
        } catch (SQLException ex) {
            Logger.getLogger(Suplier.class.getName()).log(Level.SEVERE, null, ex);
        }
        return null;
    }

    /**
     * @param kodeBarang the kodeBarang to set
     */
    public void setKodeBarang(String kodeBarang) {
        this.kodeBarang = kodeBarang;
    }

    /**
     * @param namaBarang the namaBarang to set
     */
    public void setNamaBarang(String namaBarang) {
        this.namaBarang = namaBarang;
    }

    /**
     * @param stok the stok to set
     */
    public void setStok(String stok) {
        this.stok = stok;
    }

    /**
     * @param barcode the barcode to set
     */
    public void setBarcode(String barcode) {
        this.barcode = barcode;
    }
}
